package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.FinanceHandleModel;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/16 0016.
 * 财务处理列表适配器
 */

public class FinanceHandleListAdapter extends SwipeMenuAdapter<FinanceHandleListAdapter.ViewHolder> {

//    private static final int TYPE_ITEM =0; //普通Item View
//    private static final int TYPE_FOOTER = 1; // 底部FootView

    private List<FinanceHandleModel.PCashierListDtosBean> mList;
    private Context t;

    private btClickListener listener;

    public FinanceHandleListAdapter(Context context, List<FinanceHandleModel.PCashierListDtosBean> list, btClickListener listener){
        this.mList = list;
        this.t = context;
        this.listener = listener;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        FinanceHandleModel.PCashierListDtosBean model = mList.get(position);
        holder.rmType.setText(model.getTaname());
        holder.rmNum.setText(t.getString(R.string.room_num)+t.getString(R.string.space)+model.getRoom());
        holder.balance.setText(t.getString(R.string.balance)+t.getString(R.string.space)+model.getBalance());
        holder.psCount.setText(t.getString(R.string.person_count)+t.getString(R.string.space)+model.getPersons());
        holder.arriveDate.setText(t.getString(R.string.start_stop_date)+t.getString(R.string.space)+model.getArrdate()+t.getString(R.string.zhi)+model.getDptDate());
        holder.bind(model,position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.finance_handle_list_item, parent, false);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView rmType;//房间类型
        TextView rmNum;//房间编号
        TextView balance;//余额
        TextView psCount;//人数
        TextView arriveDate;//到离日期

        Button perPersonRounds;//个人查房
        Button teamRounds;//团队查房
        Button checkOut;//结账退房
        Button audit;//查账

        public ViewHolder(View convertView) {
            super(convertView);
            rmType= (TextView) convertView.findViewById(R.id.tv_room_type);
            rmNum= (TextView) convertView.findViewById(R.id.tv_room_id);
            psCount= (TextView) convertView.findViewById(R.id.tv_person_num);
            balance= (TextView) convertView.findViewById(R.id.tv_balance);
            arriveDate= (TextView) convertView.findViewById(R.id.tv_time);

            perPersonRounds = (Button) convertView.findViewById(R.id.bt_per_person_rounds);
            teamRounds = (Button) convertView.findViewById(R.id.bt_team_person_rounds);
            checkOut = (Button) convertView.findViewById(R.id.bt_check_out);
            audit= (Button) convertView.findViewById(R.id.bt_audit);
        }

        private int position;

        private void bind(FinanceHandleModel.PCashierListDtosBean model,int pos){
            this.position=pos;
            perPersonRounds.setTag(model);
            teamRounds.setTag(model);
            checkOut.setTag(model);
            audit.setTag(model);

            perPersonRounds.setOnClickListener(this);
            teamRounds.setOnClickListener(this);
            checkOut.setOnClickListener(this);
            audit.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.bt_per_person_rounds:
                    if(listener!=null){
                        listener.onBTClickListener((FinanceHandleModel.PCashierListDtosBean) v.getTag(), R.id.bt_per_person_rounds,position);
                    }
                    break;
                case R.id.bt_audit:
                if(listener!=null){
                    listener.onBTClickListener((FinanceHandleModel.PCashierListDtosBean) v.getTag(), R.id.bt_audit,position);
                }
                break;
                case R.id.bt_check_out:
                    if(listener != null){
                        listener.onBTClickListener((FinanceHandleModel.PCashierListDtosBean) v.getTag(), R.id.bt_check_out,position);
                    }
                    break;
                case R.id.bt_team_person_rounds:
                    if(listener!=null){
                        listener.onBTClickListener((FinanceHandleModel.PCashierListDtosBean) v.getTag(), R.id.bt_team_person_rounds,position);
                    }
                    break;
            }
        }
    }

    public interface btClickListener{
        void onBTClickListener(FinanceHandleModel.PCashierListDtosBean model, int id, int position);
    }
}
